package com.googlecode.connectlet.machine.provider.key;

import java.security.spec.KeySpec;

import com.googlecode.connectlet.util.Bytes;

public class MachinePrivateKeySpec implements KeySpec {
	private byte[] encoded;

	public MachinePrivateKeySpec(byte[] encoded) {
		this.encoded = encoded;
	}

	public MachinePrivateKeySpec(MachinePrivateKey key) {
		encoded = Bytes.add(Bytes.fromShort(key.getKeySize()), key.getKey());
	}

	public byte[] getEncoded() {
		return encoded;
	}

	public MachinePrivateKey getPrivateKey() {
		return new MachinePrivateKey(Bytes.sub(encoded, 2), Bytes.toShort(encoded));
	}
}